package com.ruoyi.parkinglot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.parkinglot.domain.ParkPaymentConfig;
import com.ruoyi.parkinglot.mapper.ParkPaymentConfigMapper;
import com.ruoyi.parkinglot.service.ParkPaymentConfigService;
import com.ruoyi.parkinglot.utils.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
* @author 31713
* @description 针对表【park_payment_config(无感支付配置表 - 用于管理各停车场支付渠道配置)】的数据库操作Service实现
* @createDate 2025-02-11 13:43:45
*/
@Service
public class ParkPaymentConfigServiceImpl extends ServiceImpl<ParkPaymentConfigMapper, ParkPaymentConfig>
    implements ParkPaymentConfigService {
    @Resource
    private ParkPaymentConfigMapper baseMapper;

    @Override
    public List<ParkPaymentConfig> selectConfigList(ParkPaymentConfig config) {
        LambdaQueryWrapper<ParkPaymentConfig> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(config.getLotId() != null, ParkPaymentConfig::getLotId, config.getLotId())
                .eq(config.getPayType() != null, ParkPaymentConfig::getPayType, config.getPayType())
                .eq(config.getStatus() != null, ParkPaymentConfig::getStatus, config.getStatus())
                .eq(config.getLotId() != null, ParkPaymentConfig::getLotId, config.getLotId())
                .orderByDesc(ParkPaymentConfig::getPriority);
        return list(wrapper);
    }

    @Override
    public Result updateConfig(ParkPaymentConfig config) {
        // 使用 MyBatis-Plus 的默认更新方法
        return updateById(config) ? Result.success() : Result.error("更新失败");
    }

    @Override
    public Result deleteConfigByIds(Long[] configIds) {
        int i = baseMapper.deleteBatchIds(Arrays.asList(configIds));
        return i > 0 ? Result.success() : Result.error("删除支付配置失败");
    }

    @Override
    public Result updateConfigStatus(ParkPaymentConfig config) {
        ParkPaymentConfig updateConfig = new ParkPaymentConfig();
        updateConfig.setConfigId(config.getConfigId());
        updateConfig.setStatus(config.getStatus());
        updateConfig.setUpdateBy(SecurityUtils.getUsername());

        return updateById(updateConfig) ? Result.success() : Result.error("修改状态失败");
    }
}




